package org.nowcoder.huawei.c100;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;

/**
 * 19:火星文计算
 */
public class HC019 {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String s = br.readLine();
            solve(s);
        } catch (Exception e) {
            //throw new RuntimeException(e);
        }
    }

    private static int calExpr(int x, int y, char op) {
        if (op == '#') {
            return 2 * x + 3 * y + 4;
        } else {
            return 3 * x + y + 2;
        }
    }

    private static int[] parseInt(String s, int start) {
        int[] result = new int[2];
        StringBuilder sb = new StringBuilder();
        for (int i = start; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isDigit(c)) {
                result[1] = i;
                sb.append(c);
            } else {
                break;
            }
        }
        result[0] = Integer.parseInt(sb.toString());
        return result;
    }

    public static void solve(String s) {
        Stack<Integer> nums = new Stack<>(); //数字栈
        Stack<Character> ops = new Stack<>(); //操作符号栈
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '$') {
                int x = nums.pop();
                int[] vars = parseInt(s, i + 1);
                int y = vars[0];
                i = vars[1];
                nums.push(calExpr(x, y, '$'));
            } else if (c == '#') {
                ops.push(c);
            } else {
                int[] vars = parseInt(s, i);
                i = vars[1];
                nums.push(vars[0]);
            }
        }

        Stack<Integer> results = new Stack<>();
        while (!nums.isEmpty()) {
            results.push(nums.pop());
        }
        while (!ops.isEmpty()) {
            int x = results.pop();
            int y = results.pop();
            //从左到右计算
            results.push(calExpr(x, y, ops.pop()));
        }
        System.out.println(results.pop());
    }
}
